package com.example.demo.controller;

import com.example.demo.mapper.UserMapper;
import com.example.demo.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    UserMapper userMapper;
    @GetMapping("/")
    List<User> queryAll(){
        return userMapper.queryAll();
    }
    @GetMapping("/queryById")
    User queryById(String id){
        System.out.println(id);
        return userMapper.queryById(id);
    }
    @PostMapping("/add")
    String add(User user){
        return userMapper.add(user) == 1 ? "成功" : "失败" ;
    }
    @PostMapping("/updateById")
    String updateById(User user){
        return userMapper.updateById(user)== 1 ? "成功" : "失败" ;
    }
    @PostMapping("/delById")
    String delById(String id){
        return userMapper.delById(id)== 1 ? "成功" : "失败";
    }


}
